/**
 * 输入一个字符串，打印出该字符串中字符的所有排列。
   输入：s = "abc"
   输出：["abc","acb","bac","bca","cab","cba"]
 */

var permutation = function(s) {
    let res = [];
    let c = s.split("");
    let dfs = (x) => {
        if (x === c.length - 1) {
            res.push(c.join(""));
            return;
        }
        let dic = new Set();
        for (let i = x; i < c.length; i++) {
            if (dic.has(c[i])) continue;
            dic.add(c[i]);
            [c[i], c[x]] = [c[x], c[i]];
            dfs(x + 1);
            [c[i], c[x]] = [c[x], c[i]];
        }
    }
    dfs(0);
    return res;
}